package com.wude.guild.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.wude.guild.fragment.PayTelecomFragment;
import com.wude.http.HttpCom;
import com.wude.tools.Utils;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, HttpCom.getAppId());
        api.handleIntent(getIntent(), this);
        api.registerApp(HttpCom.getAppId());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }


    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                Utils.TS("支付失败 认证被否决");
                break;
            case BaseResp.ErrCode.ERR_COMM:
                Utils.TS("支付失败：微信支付错误");
                break;
            case BaseResp.ErrCode.ERR_OK:
                Utils.TS("微信支付成功");
                if (PayTelecomFragment.dialog.isShowing()) {
                    PayTelecomFragment.dialog.paySuccess();
                }
                break;
            case BaseResp.ErrCode.ERR_SENT_FAILED:
                Utils.TS("支付失败：发送失败");
                break;
            case BaseResp.ErrCode.ERR_UNSUPPORT:
                Utils.TS("支付失败：不支持错误");
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                Utils.TS("支付失败：用户取消");
                break;
            default:
                Utils.TS("其它");
                break;
        }
        WXPayEntryActivity.this.finish();
    }

    @Override
    public void onReq(BaseReq arg0) {
        // TODO Auto-generated method stub

    }
}